package com.qf.listener;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.FilterChainManager;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author YDW
 * projectName:project2202_4
 * time:2022/6/20 22:11
 * description:
 */
@Component
public class PreSmsListener {

    @Autowired
    FilterChainManager filterChainManager;

    @RabbitListener(queues = RabbitMQConstants.TOPIC_PRE_SEND)
    //消费队列消息
    public void consum(StandardSubmit submit,Channel channel, Message message){

        //开始处理消息 ; 如果执行策略出现问题，会发送错误日志到ES
        filterChainManager.execute(submit);


        //手动确认消息消费成功（手动ack）
        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }


    }


}
